package com.mall.service.mall;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mall.client.mall.MallMarketingService;
import com.mall.custom.dao.read.MallMarketingReadMapper;
import com.mall.custom.dao.write.MallMarketingWriteMapper;
import com.mall.pojo.MallMarketing;
import com.mall.pojo.MallMarketingExample;
import com.mall.pojo.MallMarketingExample.Criteria;
import com.mall.query.MallMarketingQuery;
import com.mall.query.Page;

@Service
public class MallMarketingServiceImpl implements MallMarketingService {
	@Autowired
	private MallMarketingReadMapper mallMarketingReadMapper;
	@Autowired
	private MallMarketingWriteMapper mallMarketingWriteMapper;

	@Override
	public List<MallMarketing> getMallMarketingListBy(MallMarketingExample example) {

		return this.mallMarketingReadMapper.selectByExample(example);
	}

	@Override
	public List<MallMarketing> getMallMarketingListByMallMarketingQuery(MallMarketingQuery mallMarketingQuery,
			Page page) {
		MallMarketingExample mallMarketingExample = new MallMarketingExample();
		if (page != null) {
			mallMarketingExample.setLimit(page.getLength());
			mallMarketingExample.setStart(page.getBegin());
		}
		Criteria criteria = mallMarketingExample.createCriteria();
		if (mallMarketingQuery.getMallId() != null && mallMarketingQuery.getMallId() > 0) {
			criteria.andMallIdEqualTo(mallMarketingQuery.getMallId());
		}
		if (mallMarketingQuery.getMallItemId() != null && mallMarketingQuery.getMallItemId() > 0) {
			criteria.andItemIdEqualTo(mallMarketingQuery.getMallItemId());
		}
		if (mallMarketingQuery.getMallItemIds() != null && mallMarketingQuery.getMallItemIds().size() > 0) {
			criteria.andItemIdIn(mallMarketingQuery.getMallItemIds());
		}
		if (mallMarketingQuery.getOnlyKey() != null && mallMarketingQuery.getOnlyKey() > 0) {
			criteria.andCommOnlyKeyEqualTo(mallMarketingQuery.getOnlyKey());
		}
		if (mallMarketingQuery.getType() != null && mallMarketingQuery.getType() > 0) {
			criteria.andTypeEqualTo(mallMarketingQuery.getType());
		}

		return this.getMallMarketingListBy(mallMarketingExample);
	}

	@Override
	public int insertMallMarketing(MallMarketing mallMarketing) {
		return this.mallMarketingWriteMapper.insertSelective(mallMarketing);
	}

	@Override
	public int updateMallMarketing(MallMarketing mallMarketing) {
		// TODO Auto-generated method stub
		return this.mallMarketingWriteMapper.updateByPrimaryKeySelective(mallMarketing);
	}

}
